package org.example.thread;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.example.netty.decoder.NettyStickyPacketLineBasedFrameServer;

import java.util.concurrent.TimeUnit;

public class DaemonThreadDemo {

    private static final Logger logger = LogManager.getLogger(DaemonThreadDemo.class);

    /**
     * 普通线程测试
     *
     * @param args
     */
    public static void main(String[] args) {
        logger.info("当前线程：{}"+ Thread.currentThread().getName());
        //创建一个用户线程，一直运行
        Thread thread = new Thread(() -> {
            while (true) {
                try {
                    TimeUnit.SECONDS.sleep(1);
                    logger.info("当前线程：【{}】,正在运行" +  Thread.currentThread().getName());
                } catch (InterruptedException e) {
                    logger.error("当前线程：{}，休眠异常：{}" +  Thread.currentThread().getName());
                }
            }
        }, "子线程");
        
        //启动线程
        thread.start();
        
        //主线程休眠2s
        try {
            TimeUnit.SECONDS.sleep(2);
            logger.info("主线程：{},休眠2s" +  Thread.currentThread().getName());
        } catch (InterruptedException e) {
            logger.error("主线程:{}休眠异常：{}" +  Thread.currentThread().getName());
        }
        
		//主线程结束，打印信息
        logger.info("主线程：{},结束运行" +  Thread.currentThread().getName());
    }
}
